#include "snowflake.h"
#include <chrono>
#include <ctime>


uint64_t SnowFlake::Generate()
{	
	uint64_t id = 0; 
	std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> tp = 
		std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
	auto tmp = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
	std::time_t timestamp = tmp.count();
	
	id = timestamp << 22;
	
	int64_t lserverid = _serverid;
	lserverid = lserverid << 12;
	

	id = id | lserverid;
	_step = 0xFFF & _step;
	id = id | _step;
	_step++;
	return id;
}
